package com.dycx.api.controller.app.food;

import com.dycx.common.RestResponse;
import com.dycx.common.annotation.Authorization;
import com.dycx.food.dto.ShoppingCartDTO;
import com.dycx.food.service.ShoppingCartFoodService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping(value = "/app/food/shoppingCart")
public class ShoppingFoodCartApiController {

    @Resource
    private ShoppingCartFoodService shoppingCartService;

    @Authorization
    @PostMapping("/add")
    public RestResponse<?> add(@RequestBody ShoppingCartDTO dto) {
        return RestResponse.success(shoppingCartService.add(dto));
    }

    @Authorization
    @GetMapping("/minus")
    public RestResponse<?> minus(Integer id) {

        return RestResponse.success(shoppingCartService.minus(id));
    }

    @Authorization
    @GetMapping("/plus")
    public RestResponse<?> plus(Integer id) {

        return RestResponse.success(shoppingCartService.plus(id));
    }

    @Authorization
    @GetMapping("/getList")
    public RestResponse<?> getList() {
        return RestResponse.success(shoppingCartService.getList());
    }

    @Authorization
    @PostMapping("/getListByIds")
    public RestResponse<?> getListByIds(@RequestBody List<Integer> ids) {
        return RestResponse.success(shoppingCartService.getListByIds(ids));
    }

    @Authorization
    @GetMapping("/clearShoppingCart")
    public RestResponse<?> clearShoppingCart() {
        return RestResponse.success(shoppingCartService.clearShoppingCart());
    }

    @Authorization
    @GetMapping("/delCart")
    public RestResponse<?> delCart(Integer cartId) {
        return shoppingCartService.delCart(cartId) ? RestResponse.success() : RestResponse.fail();
    }

    @Authorization
    @PostMapping("/delCartByIds")
    public RestResponse<?> delCartByIds(@RequestBody List<Integer> ids) {
        return shoppingCartService.delCartByIds(ids) ? RestResponse.success() : RestResponse.fail();
    }

    @Authorization
    @GetMapping("/countShoppingCart")
    public RestResponse<?> countShoppingCart() {
        return RestResponse.success(shoppingCartService.countShoppingCart());
    }

}
